<?php
//Gọi trang cấu hình
require('config.php');
//Gọi các function cần thiết
require('includes/function.php');
//Gọi trang kết nối DB
require('includes/db_connect.php');
//Kiểm tra GET ID
if (isset($_GET['id'])) {
    $id = $_GET['id'];
} else {
    header("location: index.php");
    exit();
}
?>
<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="content-type" content="text/html;charset=utf-8" />
	<meta name="author" content="Jackie Do" />
	<title>CLB Phần Mềm - Club Softwares - Cổng thông tin điện tử - The Electronic Informations Gate</title>
    <link rel="stylesheet" href="theme/<?php echo $front_end; ?>/css/styles.css" />
</head>

<body>
<?php
$query = 'SELECT * FROM news ORDER BY news_id DESC LIMIT 0, 7';
$result = mysql_query($query, $db_con);
?>
    <div id="container">
        <div id="header"></div>
        <div id="nav_bar">
            <ul id="menu">
                <li><a href="index.php" class="home_button" style="border-left: none;"></a></li>
                <li><a href="#">Menu 1</a>
                    <ul class="sub_menu">
                        <li><a href="#">Menu 1.1</a></li>
                        <li><a href="#">Menu 1.2</a></li>
                        <li><a href="#">Menu 1.3</a></li>
                    </ul>
                </li>
                <li><a href="#">Menu 2</a></li>
                <li><a href="#">Menu 3</a></li>
                <li><a href="#">Menu 4</a></li>
            </ul>
            
        </div>
        <div id="box_news">
            <?php
                $count = 1;
                while ($data = mysql_fetch_assoc($result)) {
                    if ($count >7) {
                        break;
                    } elseif ($count == 1) {
                        echo '
                        <a href="news.php?id=' .$data['news_id']. '" class="box_item_level_1" style="background: url(\'images/news/' .$data['news_img']. '\') no-repeat; background-size: 100% 100%;">
                            <div class="box_title_level_1">' .$data['news_title']. '</div>
                        </a>';
                    } else {
                        echo '
                        <a href="news.php?id=' .$data['news_id']. '" class="box_item_level_2" style="background: url(\'images/news/' .$data['news_img']. '\') no-repeat; background-size: 100% 100%;">
                            <div class="box_title_level_2">' .$data['news_title']. '</div>
                        </a>';
                    }
                    $count++;
                }
            ?>    
              
        </div>
        <div class="clear"></div>
        <div id="main_page">
            <div id="content">
                <?php
                    $query = 'SELECT * FROM news as n, categories as c, member as m WHERE news_id=' .$id. ' AND n.cate_id=c.cate_id AND n.member_id=m.member_id ORDER BY news_id DESC LIMIT 0, 10';
                    $result = mysql_query($query, $db_con);
                    if (mysql_num_rows($result) == 0) {
                        echo '<script type="text/javascript">
                            window.location = "index.php";
                        </script>"';
                        exit();
                    }
                    while ($data = mysql_fetch_assoc($result)) {
                            echo '
                            <div id="content_show">
                                <div class="content_cate">' .$data['cate_name']. '<span style="float:right;">Đăng bởi: '. $data['member_user'] . ' Vào lúc: ' .date("d/m/Y H:i:s", $data['news_date'] + $location_time*3600). '</span></div>
                                    <div id="content_detail"><h1>' .$data['news_title']. '</h1><br /><b>' . short_intro($data['news_intro'], $max_intro_length) .'</b><br /><br />
                                    ' .$data['news_full']. '<br /><div class="align_right" style="padding: 2px 20px;"><b>' .$data['news_author']. '</b></div>
                                    </div>
                                </div>';break;
                        }
                ?>    
                
            </div>
            <div id="side_right">
                    <div class="content_cate">Tin mới nhất</div>
                        <?php
                        $query = 'SELECT * FROM news ORDER BY news_id LIMIT 0, 10';
                        $result = mysql_query($query, $db_con);
                            while ($data_news = mysql_fetch_assoc($result)) {
                                echo '<div style="padding: 2px 5px;border-bottom: 1px silver dotted;"><a class="top_news" href="news.php?id=' .$data_news['news_id']. '">' .$data_news['news_title'].'</a></div>';
                            }
                        ?>  
                     <div style="padding: 2px 5px;" class="align_right"><b>Xem thêm</b></div>            
            </div>
        </div>
        <div class="clear"></div>  
        <div id="footer">
            Copyright by Clbphanmem.com
        </div>
    </div>


</body>
</html>